//处理时间戳 月日时分
export const conversionOfTime_MDhm = (time: number) => {
    let date = new Date(time);
    let M =
        (date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1) + "月-";
    let D =
        (date.getDate() + 1 < 10 ? "0" + date.getDate() : date.getDate()) +
        "日 ";
    let h =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
    let m =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    return M + D + h + m;
}

//处理时间戳 月日
export const conversionOfTime_MD = (time: number) => {
    let date = new Date(time);
    let M =
        (date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1) + "-";
    let D =
        (date.getDate() + 1 < 10 ? "0" + date.getDate() : date.getDate()) + " ";
    return M + D;
}

//处理时间戳 返回多少之前
export const funtime_date = (time: number) => {
    var now = new Date().getTime();
    //var time1=new Date(time);
    // 下面两种转换格式都可以。
    //var tmpTime = Date.parse(time.replace(/-/gi, "/"));
    //var tmpTime=time1.getTime();
    var starttime = time
    var tmpTime = (new Date(starttime)).getTime();
    // 
    var result;
    // 一分钟 1000 毫秒 乘以 60
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var week = day * 7;
    var month = day * 30;
    var year = day * 365;
    // 现在时间 减去 传入时间 得到差距时间
    var diffValue = now - tmpTime;
    // 小于 0 直接返回
    if (diffValue < 0) {
        return;

    }
    // 计算 差距时间除以 指定时间段的毫秒数
    var yearC = diffValue / year;
    var monthC = diffValue / month;
    var weekC = diffValue / week;
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    if (yearC >= 1) {
        result = "" + Math.floor(yearC) + "月前";
    } else if (monthC >= 1) {
        result = "" + Math.floor(monthC) + "月前";
    } else if (weekC >= 1) {
        result = "" + Math.floor(weekC) + "周前";
    } else if (dayC >= 1) {
        result = "" + Math.floor(dayC) + "天前";
    } else if (hourC - 8 >= 1) {
        result = "" + (Math.floor(hourC) - 8) + "小时前";
        //result = { time: parseInt(hourC), dw: '时' }

    } else if (minC >= 1) {
        result = "刚刚";
    } else {
        result = "刚刚";
    }
    return result;
}

//处理大数字转千 万 
export const numberFormat = (val: number) => {
    let num = 10000
    var sizesValue = ''
    /**
     * 判断取哪个单位
     */
    if (val < 10000) {
        // 如果小于10000则直接返回
        sizesValue = ''
        return val
    } else if (val > 10000 && val < 99999999) {
        sizesValue = '万'
    } else if (val > 100000000) {
        sizesValue = '亿'
    }
    /**
     * 大于一万则运行下方计算
     */
    let i = Math.floor(Math.log(val) / Math.log(num))
    /**
     * toFixed(0)看你们后面想要取值多少，我是不取所以填了0，一般都是取2个值
     */
    var sizes = ((val / Math.pow(num, i))).toFixed(1)
    sizes = sizes + sizesValue
    return sizes
}
